﻿using System;
using System.Text;

namespace RG.Common
{
    public static class StringMD5
    {
        /// <summary>
        /// Вычисляет от строки MD5 и кодирует в Base64
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static string MD5(this string value)
        {
            // Create a new instance of the MD5CryptoServiceProvider object.
            var md5Hasher = System.Security.Cryptography.MD5.Create();

            // Convert the input string to a byte array and compute the hash.
            var data = md5Hasher.ComputeHash(Encoding.GetEncoding("windows-1251").GetBytes(value));
            var base64data = Convert.ToBase64String(data);

            return base64data;
        }
    }
}
